/*
 * TODO: Relocate ContextButtons
 * 
 * Idea for theme: use only three user defined colors.
 */

#include "GUI.hpp"

#include <Wt/WApplication>
#include <Wt/WVBoxLayout>
#include <Wt/WCssStyleSheet>
#include "ControlButton.hpp"
#include "LeftSideOuterBorder.hpp"
#include "utilities.hpp"

#include <iostream>



//TODO: move to new file:
#include <Wt/WContainerWidget>
#include <Wt/WImage>
class ContextButtons : public Wt::WContainerWidget
{
    Wt::WHBoxLayout* layout_manager;
    
    // TODO: Move to common CSS area:
    class SilverBorder : public Wt::WCssTextRule
    {
    public:
        
        SilverBorder()
        :
        Wt::WCssTextRule(".silverborder",
                         "border-color: silver;"
                         "border-width: thick;"
                         "border-style: ridge;"
                         "display:block;"
                         "overflow:hidden;"
                         "padding: 15px; "
                         "margin: 15px;")
        {}
    };
    
public:
    ContextButtons()
    {
        setStyleClass("silverborder");
        Wt::WApplication::instance()->styleSheet().addRule(new SilverBorder);
        
        layout_manager = new Wt::WHBoxLayout;  
        
        Wt::WImage* image1 = new Wt::WImage("/resources/button-show_home.png");
        image1->setMaximumSize(70, 70);
        image1->resize(70, 70);
        
        Wt::WImage* image2 = new Wt::WImage("/resources/button-show_chart.png");
        image2->setMaximumSize(70, 70);
        image2->resize(70, 70);
        
        layout_manager->addWidget(image1);
        layout_manager->addWidget(image2);
        
        setLayout(layout_manager);
        //layout_manager->setResizable(1);
    }
    
};


// Currently used for testing:
void GUI::talkToChild()
{

    std::cout << "(TESTING: talkToChild():  We can access every child object, without needing to keep a pointer to it: "
        << itemAt(1)->layout()->itemAt(0)->layout()->itemAt(1)->widget()->height().toPixels()
        << std::endl;
}

GUI::GUI(Wt::WContainerWidget *parent=0)
:
    Wt::WHBoxLayout(parent)   
{
    
    // Currently used for testing:
    //left_side_border->mouseWentUp().connect(me, &MessagingArea::talkToChild);
    //TODO: subclass right_side_layout (RightSideLayout).
    Wt::WVBoxLayout* right_side_layout = new Wt::WVBoxLayout;  
    
    right_side_layout->addWidget(new ContextButtons,0, Wt::AlignmentFlag::AlignRight | Wt::AlignmentFlag::AlignTop);
    right_side_layout->addWidget(new ControlButton, 1, Wt::AlignmentFlag::AlignRight | Wt::AlignmentFlag::AlignBottom);                                 

    //Add the decorative, "LeftSideOuterBorder" to the left side (1st element):
    // Maybe be more readable?: -Saturday, February 01, 2014
    //addWidget(new LeftSideOuterBorder(new InnerBoder(newSplitter(top_half, bottom_half), 1);
    addWidget(new LeftSideOuterBorder, 1);
    
    addLayout(right_side_layout, 0);    
    
    // Add space around all four sides. Too bad I can't specify in %.
    setContentsMargins(50, 50, 50, 50);
    setSpacing(50); 
}

